const username = document.querySelector('.bottom')
const login = document.querySelector('button')
const reg = /^1[3-9]\d{9}$/
username.addEventListener('focus',e=>{
    if(e.target.tagName === 'INPUT'){
        e.target.style.marginTop = '35px'
    }
},true)
username.addEventListener('blur',e=>{
    if(e.target.tagName === 'INPUT'){
        if(e.target.value === ''){
            e.target.style.marginTop = '0px'
        }else{
            if(e.target.type === 'text'){
                if(!reg.test(e.target.value)){
                    document.querySelector('.utips').style.display = 'block'
                    e.target.value = ''
                }else{
                    document.querySelector('.utips').style.display = 'none'
                }   
            }else{
                if(e.target.value != '246810'){
                    document.querySelector('.ptips').style.display = 'block'
                    e.target.value = ''
                }else{
                    document.querySelector('.ptips').style.display = 'none'
                }
            }
        }
    }
},true)
login.addEventListener('click',e=>{
    if(reg.test(document.querySelector('#username').value) && document.querySelector('#password').value === '246810'){
        console.log(typeof document.querySelector('#username').value,typeof document.querySelector('#password').value);
        axios({
            url : '/v1_0/authorizations',
            method : 'Post',
            data :{
                mobile : document.querySelector('#username').value,
                code : document.querySelector('#password').value
            }
        }).then(({data:{data:res}})=>{
            localStorage.setItem('token',res.token)
            location.replace('../content/index.html')
        }).catch(error=>{
            console.dir(error);
        })
    }else{
        console.log(document.querySelector('#alert').style.top);
        document.querySelector('#alert').style.top = '100px'
        setTimeout(() => {
            document.querySelector('#alert').style.top = '-100px'
        }, 1500);
    }
})